home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  588 b   |  20 lines

  1. /*  fread.c, from p. 429 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     int numread;
  6.     FILE *infile;
  7.     char filename[80], buffer[80];
  8.     printf("Enter name of a text file: ");
  9.     gets(filename);
  10.                 /*  Open the file for reading  */
  11.     if ((infile = fopen(filename, "rb")) == NULL)
  12.     {
  13.     printf("fopen failed.\n");
  14.     exit(0);
  15.     }
  16.                 /*  Read 80 characters and display the  */
  17.                 /*   buffer                             */
  18.     numread = fread((void *)buffer, sizeof(char), 80, infile);
  19.     printf("Read these %d characters:\n %s\n", numread, buffer);
  20. }